package graph.mcg;

import java.util.ArrayList;
import java.util.List;

import spec.ocl_mcg.IfExpNode;
import spec.ocl_mcg.TreeNode;

public class AlternativeNode extends CGNode {

	// field
	private TreeNode referencednode;
	private BranchNode bnode = new BranchNode();
	private ConstraintNode truescondition = new ConstraintNode();;
	private ConstraintNode falsecondition = new ConstraintNode();;

	private CGNode node_then;
	private CGNode node_else;

//	public AlternativeNode(String condition, CGNode nodethen, CGNode nodeelse) {
//		this.condition = condition;
//		node_then = nodethen;
//		node_else = nodeelse;
//
//		truestatement.setStatement(condition);
//		truestatement.setOp("#<");
//		truestatement.setExp1("Counter");
//		truestatement.setExp2("Limit");
//
//		truestatement.setNextnode(node_then);
//		// node_then = truestatement;
//
//		falsestatement.setStatement("neg(" + condition + ")");
//		falsestatement.setOp("neg");
//		falsestatement.setExp1(condition);
//
//		falsestatement.setNextnode(node_else);
//	}

	public AlternativeNode(IfExpNode node) {
		referencednode = node;
		
		bnode.setTnode(truescondition);
		bnode.setFnode(falsecondition);		

		// true
		truescondition.setConstraint(node.getExpresult());
		node_then = node.getNode_then().toCG();		
		truescondition.setNextnode(node_then);

		// false
		falsecondition.setConstraint("neg(" + node.getExpresult() + ")");
		node_else = node.getNode_else().toCG();
		falsecondition.setNextnode(node_else);
	}

	public void setNextnode(CGNode nextnode) {
		CGNode temp = node_then;
		while(temp.getNextnode()!=null){
			temp = temp.getNextnode();
		}
		temp.setNextnode(nextnode);
		
		temp = node_else;
		while(temp.getNextnode()!=null){
			temp = temp.getNextnode();
		}
		temp.setNextnode(nextnode);
		this.nextnode = nextnode;
	}

	public ConstraintNode getTruestatement() {
		return truescondition;
	}

	public void setTruestatement(ConstraintNode truestatement) {
		this.truescondition = truestatement;
	}

	public ConstraintNode getFalsestatement() {
		return falsecondition;
	}

	public void setFalsestatement(ConstraintNode falsestatement) {
		this.falsecondition = falsestatement;
	}

	public CGNode getNode_then() {
		return node_then;
	}

	public void setNode_then(CGNode nodeThen) {
		node_then = nodeThen;
	}

	public CGNode getNode_else() {
		return node_else;
	}

	public void setNode_else(CGNode nodeElse) {
		node_else = nodeElse;
	}

	public BranchNode getBnode() {
		return bnode;
	}

	public void setBnode(BranchNode bnode) {
		this.bnode = bnode;
	}

	@Override
	public List<CGNode> nextPossibleNodes() {
		// TODO Auto-generated method stub
		ArrayList<CGNode> nodes = new ArrayList<CGNode>();
		nodes.add(bnode);
		//nodes.add(falsecondition);

		return nodes;
	}

	@Override
	public String greateCLPTerm() {
		// TODO Auto-generated method stub
		return null;
	}

}
